﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework;

namespace Ue.Qcdz.Domain.SaleCategorys
{
    public class SaleCategoryService
    {
        private static ISaleCategoryRepository repository;

        static SaleCategoryService()
        {
            SaleCategoryService.repository = RepositoryFactory.GetRepository<ISaleCategoryRepository, SaleCategory>();
        }
        public static SaleCategory GetSaleCategory(object saleCategoryKey)
        {
            return SaleCategoryService.repository.FindBy(saleCategoryKey);
        }

        public static IList<SaleCategory> GetSaleCategory()
        {
            return SaleCategoryService.repository.FindAll();
        }
        public static IDataResult<SaleCategory> GetSaleCategory(ISaleCategoryDataQuery dataQuery)
        {
            return SaleCategoryService.repository.FindBy(dataQuery);
        }

        public static void AddSaleCategory(SaleCategory saleCategory)
        {
            SaleCategoryService.repository.Add(saleCategory);
        }

        public static void RemoveSaleCategory(SaleCategory saleCategory)
        {
            SaleCategoryService.repository.Remove(saleCategory);
        }
        public static void RemoveSaleCategory(object saleCategoryKey)
        {
            SaleCategory saleCategory = SaleCategoryService.repository.FindBy(saleCategoryKey);
            if (saleCategory == null)
            {
                throw new ArgumentOutOfRangeException("salecategoryKey");
            }

            SaleCategoryService.repository.Remove(saleCategory);
        }

        public static void UpdateSaleCategory(SaleCategory saleCategory)
        {
            SaleCategoryService.repository[saleCategory.Key] = saleCategory;
        }

        /// <summary>
        /// 删除所有分类
        /// </summary>
        /// <param name="shop"></param>
        public static void RemoveAll(Shops.Shop shop)
        {
            SaleCategoryService.repository.RemoveAll(shop);
        }
    }
}
